package com.elm.serviceimpl;


import com.elm.dao.UserDao;

import com.elm.daoimpl.UserDaoImpl;
import com.elm.model.User;
import com.elm.service.UserService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;



public class UserServiceImpl implements UserService{

	UserDao userdao = new UserDaoImpl();
	@Override
	public boolean validateUname(String uname) {
		
		return userdao.validateUname(uname);
	}
	@Override
	public boolean validateUphone(String uphone) {
		// TODO Auto-generated method stub
		return userdao.validateUphone(uphone);
	}
	@Override
	public boolean userRegist(User u) {
		// TODO Auto-generated method stub
		return userdao.addUser(u);
	}
	@Override
	public User userLogin(User u) {
		// TODO Auto-generated method stub
		return userdao.validateUser(u);
	}

	/**
	 * 通过名字查询
	 * 将查询出来的用户转换成json数组
	 */
			
	   JSONObject json=new JSONObject();
	public JSONObject FindUserByName(int start, int pageSize, String searchname)  {	
			json.put("total", userdao.getUsersCountByName(searchname));
			json.put("rows", JSONArray.fromObject(userdao.FindUserByName(start,pageSize,searchname)));		
			 return json;	     
		}
	/**
	 * 查询全部用户
	 */
		public JSONObject FindAllUsers(int start, int pageSize) {
			json.put("total", userdao.getUsersCount());
			json.put("rows", JSONArray.fromObject(userdao.FindAllUsers(start,pageSize)));
				return json;
		}
	/**
	 * 通过id来删除用户
	 */
		public boolean deleteuser(int usid) {
			// TODO Auto-generated method stub
			if(userdao.deleteuser(usid)==true){
				return true;
			}
			return false;
		}
/**
 * 查找全部过往用户
 */
	public JSONObject FindOldUsers(int start, int pageSize) {
		json.put("total", userdao.getOldUsersCount());
		json.put("rows", JSONArray.fromObject(userdao.FindOldUsers(start, pageSize)));
			return json;
	}
	/**
	 * 通过名字查找过往用户
	 */
	public JSONObject FindOldUserByName(int start, int pageSize, String searchname) {
		json.put("total", userdao.getOldUserCountByName(searchname));
		json.put("rows", JSONArray.fromObject(userdao.FindOldUserByName(start, pageSize, searchname)));		
		 return json;	 
	}
	/**
	 * 通过id来还原用户
	 */
	public boolean restoreuser(int usid) {
		if(userdao.restoreuser(usid)==true){
			return true;
		}
		return false;
	}


}
